/*
Purpose: Generate arrest rate table using reading scores
*/

*reading in state naep scores
use "data/clean/naep_data_read.dta", clear
keep fips yob read08sd98_gap1
statastates ,fips(fips)
drop if _merge==2
drop _merge
rename state_abbrev state
save "data/clean/statenaepscores_read",replace

*reading in donahue data
use "data/raw/arrests by state year and yob.dta", clear
destring l_arrs_cap_vio, replace force
destring l_arrs_cap_pro, replace force

gen yob=relevant_yob

merge m:1 fips yob using "data/clean/statenaepscores_read"

*not using dc or those born before 1985...otherwise perfect match
drop if _merge==1|_merge==2
drop if fips==11
drop _merge

ren fips fips_birth

merge m:1 fips_birth yob using "data/clean/state_year_ses_index" //bringing in parental education variables
keep if _merge==3
drop _merge

ren fips_birth fips


recode fips (9 23 25 33 44 50 =1 "New England") (34 36 42 =2 "Mid Atlantic") (17 18 26 39 55 =3 "E North Central")  (19 20 27 29 31 38 46 = 4 "W North Central") (10 11 12 13 24 37 45 51 54 =5 "South Atlantic") (1 21 28 47 =6 "E South Central") (5 22 40 48 =7 "W South Central")  (4 8 16 30 32 35 49 56 =8 "Mountain")  (2 6 15 41 53 = 9 "Pacific"),gen(division_birth)

capture drop fips_yob
egen fips_yob=group(fips yob)

eststo clear
//running our main specification on violent and property crime
eststo vio: quietly reg l_arrs_cap_vio read08sd98_gap1 norm_either_par_gcol_2yr division_birth#yob age#year i.fips [pw=seer_pop] ,robust cluster(fips_yob)
eststo pro: quietly reg l_arrs_cap_pro read08sd98_gap1 norm_either_par_gcol_2yr division_birth#yob age#year i.fips [pw=seer_pop] ,robust cluster(fips_yob)
esttab using "results/arrests and scores_read",  mlabel("violent crimes" "property crimes") csv cells(b(star fmt(3))  se(par fmt(3))) replace label order(read08sd98_gap1 norm_either_par_gcol_2yr)

// bringing in math scores to compare with reading

*reading in donahue data
use "data/raw/arrests by state year and yob.dta", clear
destring l_arrs_cap_vio, replace force
destring l_arrs_cap_pro, replace force

gen yob=relevant_yob

merge m:1 fips yob using statenaepscores

*not using dc or those born before 1987...otherwise perfect match
drop if _merge==1|_merge==2
drop if fips==11
drop _merge

ren fips fips_birth

merge m:1 fips_birth yob using "data/clean/state_year_ses_index" //bringing in parental education variables
keep if _merge==3
drop _merge

ren fips_birth fips


recode fips (9 23 25 33 44 50 =1 "New England") (34 36 42 =2 "Mid Atlantic") (17 18 26 39 55 =3 "E North Central")  (19 20 27 29 31 38 46 = 4 "W North Central") (10 11 12 13 24 37 45 51 54 =5 "South Atlantic") (1 21 28 47 =6 "E South Central") (5 22 40 48 =7 "W South Central")  (4 8 16 30 32 35 49 56 =8 "Mountain")  (2 6 15 41 53 = 9 "Pacific"),gen(division_birth)

capture drop fips_yob
egen fips_yob=group(fips yob)

eststo clear
//only using 1983 cohorts onward for comparability with reading
eststo vio: quietly reg l_arrs_cap_vio math08sd92_gap1 norm_either_par_gcol_2yr division_birth#yob age#year i.fips [pw=seer_pop] if yob>=1983,robust cluster(fips_yob)
eststo pro: quietly reg l_arrs_cap_pro math08sd92_gap1 norm_either_par_gcol_2yr division_birth#yob age#year i.fips [pw=seer_pop] if yob>=1983,robust cluster(fips_yob)
esttab using "results/arrests and scores_1983yob",  mlabel("violent crimes" "property crimes") csv cells(b(star fmt(3))  se(par fmt(3))) replace label order(math08sd92_gap1 norm_either_par_gcol_2yr)